<template>
	<view class="content reg-page">
		<view class="input-group">
			<view class="input-column border-bottom-1px">
				<text class="title">公司名称</text>
				<view class="input-item">
					<input class="padding-10" placeholder="请输入公司名称" v-model="workData.company" />
				</view>
			</view>
			<view class="input-column border-bottom-1px" @click="toIndustry(3)">
				<text class="title">所在行业</text>
				<view class="space-between-algin row padding-height-20">
					<input class="padding-10" disabled="true" placeholder="请选择所在行业":value="workData.companyBusiness||'行业不限'" />
					<text class="yzb yzb-next"></text>
				</view>
			</view>

			<view class="input-column border-bottom-1px">
				<text class="title">在职时间</text>
				<view class="row space-between-algin">
					<picker mode="date" :value="workData.workTimeBegin" :start="startDate" :end="endDate" @change="bindDate1Change">
						<input class="padding-10" disabled placeholder="开始时间" :value="workData.workTimeBegin.slice(0,10)" />
					</picker>
					至
					<picker mode="date" :value="workData.workTimeEnd" :start="startDate" :end="endDate" @change="bindDate2Change">
						<input class="padding-10" disabled style="text-align: center;" placeholder="结束时间" :value="workData.workTimeEnd.slice(0,10)" />
					</picker>
				</view>
			</view>
			
			<view class="input-column border-bottom-1px" @click="toPost(3)">
				<text class="title">职位名称</text>
				<view class="space-between-algin row padding-height-20">
					<input class="padding-10" disabled="true" placeholder="请选择期望职位" v-model="workData.workTitle" />
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px" @click="toWorkContent(workData.workContent)">
				<text class="title">工作内容</text>
				<view class="space-between-algin row padding-height-20">
					<view class="two-ellipsis">{{workData.workContent}}</view>
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">所属部门(选填)</text>
				<view class="space-between-algin row padding-height-20">
					<input class="padding-10" placeholder="请填入部门名称" v-model="workData.workDept" maxlength="10"/>
				</view>
			</view>
			<view class="flex border-bottom-1px">
				<text class="title flex-1" style="position:relative;top:42rpx;left:36rpx;">对这家公司隐藏我的</text>
				<view class="row padding-height-20">
					<switch class="section-right" color="#84C0F4" :checked="workData.showToCompany" @change="switchChange"/>
				</view>				
			</view>			
		</view>
		<view class="btn-row row flex jcsb">
			<button v-if="expWorkId" type="warn" class="btn-delete" @tap="remove(expWorkId)">删除</button>
			<button type="primary" class="btn-save" :class="expWorkId ? 'width-55' : 'width-90'" @tap="register">保存</button>
		</view>		
	</view>
</template>

<script>
import { mapState } from 'vuex';
import {
		formatDate,
		calCurrentYear
	} from '@/common/date';
export default {
	components: {
	},
	computed: {
		...mapState(['openId', 'customerInfo','expWorkList']),
		startDate() {
			return this.getDate('start');
		},
		endDate() {
			return this.getDate('end');
		}
	},	
	data() {
		const currentDate = this.getDate({format: true});
		const currentTime = this.getTime({format: true});//当前时间
		return {
			bindTimee: currentTime,
			expWorkId:'',
			resumeId:'',
			treatmentStatu: { checked: true },
			workData:{
				company:'',//公司名称
				companyBusiness: '行业不限',//所在行业
				industryList:[],
				selectIndustryIds: '0',
				workContent:'',//工作内容
				workDept:'',//所属部门
				workTitle:'',//职位名称				
				workTimeBegin: '',//在职开始时间
				workTimeEnd: '',//在职结束时间
				showToCompany:0,//对这家公司隐藏我的信息 0显示1隐藏
			},
			
			selectPost: {
				name: '',
				id: ''
			},
			selectIndustrys: null,			
			skills:[],
			dialogTitle:'添加关键词',
			value:"",
		};
	},
	onLoad(query) {	
		this.expWorkId = query.expWorkId
		this.resumeId = query.resumeId
		if(this.expWorkId){
			this.getDetail()
		}		
	},
	onShow() {
		
	},
	methods: {	
		//详情
		async getDetail(){
			var that = this
			let res= await this.$apis.getDetailWorkInfo(this.expWorkId);
			if(res){				
				res.data.workTimeBegin = res.data.workTimeBegin.slice(0,10)
				res.data.workTimeEnd = res.data.workTimeEnd.slice(0,10)
				that.workData = res.data
			}
		},
		//工作开始时间
		bindDate1Change: function(e) {
			this.workData.workTimeBegin = e.target.value;
		},
		//工作结束时间
		bindDate2Change: function(e) {
			this.workData.workTimeEnd = e.target.value;
		},
		//所在行业
		toIndustry(type) {
			this.$mRouter.push({
				route: this.$mRoutesConfig.industry,
				query: {
					choicetype: type
				}
			});
		},
		//职位名称
		toPost(type) {
			this.$mRouter.push({
				route: this.$mRoutesConfig.post,
				query: {
					Typevalue: type
				}
			});
		},
		//工作内容
		toWorkContent(workContent) {
			this.$mRouter.push({
				route: this.$mRoutesConfig.editWorkContent,
				query: {
					id: 1,
					content:workContent,
				}
			});
		},
		//对这家公司隐藏
		switchChange (e) {
			let value = e.target.value
			if(value == true){
				this.workData.showToCompany = 1
			}else{
				this.workData.showToCompany = 0
			}
		},
		// 点击注册按钮
		async register() {			
			if (!this.workData.company) {
				uni.showToast({
					icon: 'none',
					title: '请输入公司名称'
				});
				return;
			}
			if (!this.workData.workTitle) {
				uni.showToast({
					icon: 'none',
					title: '请选择职位'
				});
				return;
			}
			if (!this.workData.workContent) {
				uni.showToast({
					icon: 'none',
					title: '请输入工作内容'
				});
				return;
			}			
			if (!this.workData.workTimeBegin) {
				uni.showToast({
					icon: 'none',
					title: '请选择在职时间'
				});
				return;
			}
			this.workData.workTimeBegin = this.workData.workTimeBegin+' '+ this.bindTimee+":00"
			this.workData.workTimeEnd = this.workData.workTimeEnd+' '+ this.bindTimee+":00"			
			if(!this.expWorkId){
				//新增
				this.workData.resumeId = this.resumeId
				let res=await this.$apis.addWorkInfo(this.workData);
				if(res){
					uni.navigateBack({
						delta:1
					})
				}				
			}else{
				//修改
				let res = await this.$apis.eidtWorkInfo(this.workData);
				if(res){
					uni.navigateBack({
						delta:1
					})
				}
			}
			
		},
		//删除
		async remove(expWorkId){
			let res=await this.$apis.deltelWorkInfo(expWorkId);
			if(res){
				uni.navigateBack({
					delta:1
				})
			}
		},		
		deleteImg(index){
			this.skills.splice(index,1);
		},
		formatDates(time){
			if (time == null || time === '') {
			  return 'N/A';
			}
			let date = new Date(time);
			// return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
			return formatDate(date, 'yyyy-MM-dd')
		},
		getDate(type) {
			const date = new Date();
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();
		
			if (type === 'start') {
				year = year - 60;
			} else if (type === 'end') {
				year = year + 2;
			}
			month = month > 9 ? month : '0' + month;
			day = day > 9 ? day : '0' + day;
			return `${year}-${month}-${day}`;
		},
		// 获取当前时间
		getTime(type) {
			const date = new Date();
			let hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
			let minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
			return `${hour}:${minute}`;
		},
	}
};
</script>

<style lang="scss" scoped>
input {
	width: 90%;
}
.input-group {
	border-radius: 10upx;
	margin-top: 10upx;
	overflow: hidden;
	margin-bottom: 120upx;
}

.input-row {
	display: flex;
	flex-direction: row;
	position: relative;
	background: #fff;
	justify-content: space-between;
	align-items: center;
	padding: 15upx 10upx;
}

.input-row .title {
	width: 25%;
	padding: 20upx 0;
	padding-left: 20upx;
	line-height: 50upx;
	font-size: 28rpx;
}

.border-bottom-1px {
	position: relative;

	&::after {
		position: absolute;
		z-index: 1;
		right: 0;
		bottom: 0;
		left: 20upx;
		height: 1upx;
		content: '';
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		background-color: #e2e2e2;
	}
}

.header {
	display: flex;
	flex-direction: column;
	.tip {
		font-size: 28rpx;
		color: #666;
		margin-left: 20upx;
	}
}

.head-img {
	margin-right: 15upx;
	image {
		width: 160upx;
		height: 160upx;
		border-radius: 50%;
	}
}

radio-group {
	margin-right: 10upx;
}

.radio {
	margin-left: 20upx;
}

.input-column {
	display: flex;
	flex-direction: column;
	background-color: #fff;
	padding: 30upx 20upx 10upx 20upx;

	.title {
		margin-left: 10upx;
		font-size: 28rpx;
	}

	.input-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.picker {
		padding: 30upx 0;
		margin-left: 10upx;
		position: relative;
		picker {
			font-size: 28rpx;
			width: 100%;
			position: absolute;
		}
	}
	.yzb-next {
		float: right;
		color: #999;
	}
}

.content {
	background: #fff;
}

.btn-row {
	position: fixed;
	z-index: 99;
	bottom: 0upx;
	padding: 20upx 0;
	background-color: #ffffff;
	width: 100%;
	padding-bottom: constant(safe-area-inset-bottom);
	padding-bottom: env(safe-area-inset-bottom);
	box-sizing: content-box;	
	.btn-delete {
		background-color: #ccc;
		height: 90upx;
		line-height: 90upx;
		font-size:34rpx;
		color:#333;
		width: 50%;
	}

	.btn-save {
		background-color: #84C0F4;
		height: 90upx;
		line-height: 90upx;
		font-size:34rpx;
	}
	.width-55 {
		width: 50%;
	}

	.width-90 {
		width: 90%;
		display: block;
		margin: 0 auto;
	}
}


.text-blue {
	color: $main-color;
	border: 1upx solid $main-color;
	background-color: $main-color;
	color: #ffffff;
}
.text-normal {
	color: $font-color-666;
	border: 1upx solid $border-color-base;
}

.skill-item {
	padding: 20upx;
	flex-wrap: wrap;
	display: flex;
	.skill-item-item{
		position: relative;
		margin-right: 20upx;
	}
	.item {
		font-size: $uni-font-size-sm;
		padding: 12upx 20upx;
		margin-right: 20upx;
		margin-bottom: 20upx;
		// background-color: $border-color-base;
		border-radius: 8upx;
		// color: $font-color-666;
	}
}
</style>
